package com.yuexunit.operationman.nbsy.module.InterventionalOperation.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.Bean.FlaxmeterBean;
import com.yuexunit.operationman.nbsy.widget.FlaxMeterDialog;

/**
 * Created by chenss on 2017/9/7 0007.
 */

public class AddFlaxMeterItem {

    Context context;
    FlaxMeterDialog dialog;

    public AddFlaxMeterItem(Context context){
        this.context = context;
    }

    /**
     *
     * @param
     * @return
     */
    public View itemView(final FlaxmeterBean flaxmeterBean) {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        View view = LayoutInflater.from(context).inflate(R.layout.item_flaxmeter_view, null);//也可以从XML中加载布局

        view.setLayoutParams(lp);//设置布局参数

        final TextView time = (TextView) view.findViewById(R.id.flaxmeter_time);
        final TextView rate = (TextView) view.findViewById(R.id.flaxmeter_rate);
        final TextView bp = (TextView) view.findViewById(R.id.flaxmeter_bp);
        final TextView saturation = (TextView) view.findViewById(R.id.flaxmeter_saturation);

        time.setText(flaxmeterBean.getTime());
        rate.setText(flaxmeterBean.getRate());
        if(flaxmeterBean.getDbp().isEmpty() && flaxmeterBean.getSbp().isEmpty()){
            bp.setText("");
        }else{
            bp.setText(flaxmeterBean.getDbp() + "/" + flaxmeterBean.getSbp());
        }
        saturation.setText(flaxmeterBean.getSaturation());

        time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog = new FlaxMeterDialog(context, false).builder();
                dialog.setTitle("请输入时间", "原时间" + time.getText().toString());
                dialog.setDtata(time.getText().toString(), 60);
                dialog.setCallBack(new FlaxMeterDialog.ICallBack() {
                    @Override
                    public void callback(Bundle bundle) {
                        flaxmeterBean.setTime(bundle.getString("content"));
                        time.setText(bundle.getString("content"));
                        dialog.dismiss();
                    }
                });
                dialog.show();
            }
        });

        rate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog = new FlaxMeterDialog(context, false).builder();
                dialog.setTitle("请输入心率值", "原时间" + time.getText().toString());
                dialog.setDtata(rate.getText().toString(), 220);
                dialog.setCallBack(new FlaxMeterDialog.ICallBack() {
                    @Override
                    public void callback(Bundle bundle) {
                        flaxmeterBean.setRate(bundle.getString("content"));
                        rate.setText(bundle.getString("content"));
                        dialog.dismiss();
                    }
                });
                dialog.show();
            }
        });

        bp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog = new FlaxMeterDialog(context, true).builder();
                dialog.setTitle("请输入血压值", "原时间" + time.getText().toString());
                dialog.setBp(flaxmeterBean.getSbp(), flaxmeterBean.getDbp());
                dialog.setCallBack(new FlaxMeterDialog.ICallBack() {
                    @Override
                    public void callback(Bundle bundle) {
                        flaxmeterBean.setDbp(bundle.getString("dbp"));
                        flaxmeterBean.setSbp(bundle.getString("sbp"));
                        bp.setText(bundle.getString("dbp") + "/" + bundle.getString("sbp"));
                        dialog.dismiss();
                    }
                });
                dialog.show();
            }
        });

        saturation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog = new FlaxMeterDialog(context, false).builder();
                dialog.setTitle("请输入氧饱和度", "原时间" + time.getText().toString());
                dialog.setDtata(saturation.getText().toString(), 100);
                dialog.setCallBack(new FlaxMeterDialog.ICallBack() {
                    @Override
                    public void callback(Bundle bundle) {
                        flaxmeterBean.setSaturation(bundle.getString("content"));
                        saturation.setText(bundle.getString("content"));
                        dialog.dismiss();
                    }
                });
                dialog.show();
            }
        });

        return view;
    }
}
